/**
 * Copyright (c) 2009-2011, chunquedong(YangJiandong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 
 * History:
 *     2010-05-05  Jed Young  Creation
 */
package chunmap.view.layer;

import chunmap.view.Renderer;
import chunmap.view.render.GeneralSymbol;
import chunmap.view.render.Symbol;

/**
 * @author chunquedong
 * 
 */
public abstract class AbstractLayer implements Layer {

	private boolean editable;
	private boolean visible = true;
	private String name;
	private double minScale = 0.001;
	private double maxScale = 10000000;

	public boolean isEditable() {
		return editable;
	}

	public void setEditable(boolean editable) {
		this.editable = editable;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public boolean isVisible() {
		return visible;
	}

	@Override
	public void setVisible(boolean visible) {
		this.visible = visible;

	}

	public double getMinScale() {
		return minScale;
	}

	public void setMinScale(double minScale) {
		this.minScale = minScale;
	}

	public double getMaxScale() {
		return maxScale;
	}

	public void setMaxScale(double maxScale) {
		this.maxScale = maxScale;
	}

	@Override
	public void render(Renderer r) {
		if (!visible)
			return;
//		if (r.getScale() > maxScale)
//			return;
//		if (r.getScale() < minScale)
//			return;
		drawProcess(r);
	}

	protected abstract void subRender(Symbol smb,int i, Renderer r);
	
	private void drawProcess(Renderer r) {
		for(int i=0;i<defaultStyle.length;i++){
			final Symbol smb=defaultStyle[i];
			subRender(smb,i,r);
		}
	}
	
	private Symbol[] defaultStyle=new Symbol[]{new GeneralSymbol()};
	public Symbol[] getDefaultStyle() {return defaultStyle;}
	public void setDefaultStyle(Symbol[] style) {this.defaultStyle = style;}
}